1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import requests from bs4 import BeautifulSoup
headersPara = { 'Connection': 'Keep-Alive', 'Accept': 'text/html, application/xhtml+xml, */*', 'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Mozilla/6.1 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko' } url="https://www.baidu.com/s" f=open('./phonenumber.txt','w')
for i in range(111,119): word="13363460"+str(i) print(i) f.write(word+' ') data={ 'wd':word, 'ie':'utf-8' } response =requests.get(url=url,params=data,headers=headersPara) response.encoding="utf-8" html=response.text soup=BeautifulSoup(html,'lxml') data=soup.select('.c-gap-bottom-small span') if data and data[1]: f.write(data[1].get_text()) f.write('\n')
f.close()
|